<%@ page language="java" contentType= "text/html" pageEncoding="UTF-8"%>
<%@ page import="com.jm.web.form.TableToolbar" %>
<%@ page import="com.jm.web.form.Button" %>
<%@ page import="com.jm.web.form.Empty" %>
<%@ page import="com.jm.web.form.Toolbar" %>
<%@include file="/include/common/griduihead1.jsp"%>
<%@include file="/include/common/griduihead2.jsp"%>
<%
	page1.setWelcome(false);//禁用欢迎信息
	page1.getPageTitle().setTitle("加工點选择页面");
	page1.setMinWidth(500);
	page1.setSpOpen(false);
	boolean bsingle = form.gpbv("single",false);
	String strValue = form.gpsv("value");
	String strSys004aSn = form.gpsv("sys004aSn");
	String strVdr = form.gpsv("vdr");
%>
<jm:form>
<input type="hidden" name="single" value="<%=bsingle%>" />
<input type="hidden" name="value" value="<%=strValue%>" />
<input type="hidden" name="sys004aSn" value="<%=strSys004aSn%>" />
<input type="hidden" name="vdr" value="<%=strVdr%>" />
<jm:layout postion="north">
	<jm:toolbar newEnab="false" saveEnab="false" cancelEnab="false" deleteEnab="false" copyEnab="false" startEnab="false" checkEnab="false" exportEnab="false" printEnab="false" helpEnab="false"/>
	<jm:pageTitle />
	<jm:sp id="sp1" data="<%=Utils.TAG_FORM%>" tabSize="1" keydownConfig="code:'enter',action:'search'">
		<jm:tab colModel="180;180;*">
			<input caption="廠商代號%" captionWidth="70px" width="90px" name="codeName" type="text" />
			<input caption="簡稱%" captionWidth="70px"  width="90px" name="shortName" type="text" />
			<input caption="中文全稱%" captionWidth="70px"  width="90px" name="fullName" type="text" />
		</jm:tab>
	</jm:sp>
	<jm:error></jm:error>
</jm:layout>

<jm:layout postion="center" export="true">
	<jm:table id="grid1" dataSet="<%=ret.getSerchResult()%>">
		<jm:thead >
			<tr>
				<td>
					<keep>
						選
						<%if(!bsingle){%>
						<input type="checkbox" name="allselect" id="allselect" value="1" onclick="$('[name=itemselect]').attr('checked',this.checked);$('[name=groups]').attr('checked',this.checked);" />	
						<%}%>
					</keep>
				</td>
				<td>廠商代號</td>
				<td>簡稱</td>
				<td>中文全稱</td>
			</tr>
		</jm:thead>
		<jm:tbody >
			<%  
				ResultSet rs = (ResultSet)ret.getTableRow();
				String tempValue = utils.getRsString(rs, "codeName");
			%>
		    <tr>
		       <TD>
		           <input type="checkbox" name="itemselect" text="<%=utils.getRsString(rs, "shortName")%>" value="<%=tempValue%>" <%=strValue.equals(tempValue) ? "checked" : ""%> <%=bsingle ? "onmousedown=\"$('[name=itemselect]').removeAttr('checked');\"" : ""%> />
		       </TD>
		       <TD><%=utils.getRsString(rs, "codeName")%></TD>
		       <TD><%=utils.getRsString(rs, "shortName")%></TD>
		       <TD><%=utils.getRsString(rs, "chfullName")%></TD>	       
		    </tr>
		</jm:tbody>
		<jm:tfoot>
		</jm:tfoot>
	</jm:table>
</jm:layout>

<jm:layout postion="south">
	<%
		TableToolbar toolbar = new TableToolbar();
		toolbar.InitTag(null);
		toolbar.getAddRowButton().setEnab(false);
		toolbar.init();
		toolbar.setLeft(false);
		
		Button calBtn = Toolbar.getNewButton("取消操作","okbtn","okbtn","ax-btn-icon sx-tb-cancel",null);
		calBtn.setWidth("100px");
		calBtn.setOnClick("top.close();");
		Button emptyBtn = Toolbar.getNewButton("清空選擇","okbtn","okbtn","ax-btn-icon sx-tb-restart",null);
		emptyBtn.setWidth("100px");
		emptyBtn.setOnClick("fun_empty();");
		Button okBtn = Toolbar.getNewButton("確定選擇","okbtn","okbtn","ax-btn-icon sx-tb-ok",null);
		okBtn.setWidth("100px");
		okBtn.setOnClick("fun_ok();");
		
		Empty empty = new Empty();
		empty.setWidth("100%");
		toolbar.getItems().clear();
		toolbar.getItems().add(empty);
		toolbar.getItems().add(calBtn);
		toolbar.getItems().add(emptyBtn);
		toolbar.getItems().add(okBtn);
	%>
	<div align="right">
	<%toolbar.onRender(out);%>
	</div>
</jm:layout>
</jm:form>
<jm:script><script type="text/javascript" charset="UTF-8">
	var config = top.dialogArguments;
	top.returnValue = {}; 
	
	function fun_empty(){
		if('table' == config['type']){
			top.returnValue['action'] = 'set';
		}else{
			top.returnValue['action'] = 'clear';
		}
		top.close();
	}
	
	function fun_ok(){
		top.returnValue['action'] = 'set';
		var value = '';
		var text = '';
		var bfirst = true;
		var split = $P.gv(config['split'],',');
		var valueAy = [];
		var textAy = [];
		
		if('table' == config['type']){
			$('[name=itemselect]:checked').each(function(){
				valueAy.push($(this).val());
				textAy.push($(this).attr('text'));
			});
			
			top.returnValue['value'] = valueAy;
			top.returnValue['text'] = textAy;
		}else{
			$('[name=itemselect]:checked').each(function(){
				if($P.gv($(this).val()) != ''){
					if(!bfirst){
						value += split;
						text += split;
					}else{
						bfirst = false;
					}
					value += $(this).val();
					text +=$(this).gv('text');
				}
			});
			top.returnValue['value'] = value;
			top.returnValue['text'] = text;
		}
		top.close();
	}
	
	function ts(arg){
		if(arg == undefined)
			return '';
		for(var i=0;i<10;i++){
			var streg = '\\\%'+(i+1)+'\\\$s';
			arg = arg.replace(new RegExp(streg,'gm'),'{'+i+'}');
		}
		return arg;
	}
</script></jm:script>
<%@include file="/include/common/griduiend.jsp"%>